var app=getApp();
var ux = require('../../../../lib/ux.js');
var WxParse = require('../../../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {    
    obj:{},
    action:"/api/articles/getADetails.do",
	submit:"{{submit}}"
  },
  totoChong: function () {
    wx.navigateTo({
      url: '/pages/member/tab3/recharge/recharge?id=' + this.data.obj.goods.id,
    })
  },
  totoShopDetail:function(){
    wx.navigateTo({
      url: '/pages/member/tab1/shop/detail?prices=' + this.data.obj.goods.price + '&id=' + this.data.obj.goods.id,
    })
  },
  gotoDetails: function (event) {
    var dataset = event.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/member/tab1/articel/articleDetail?aId=' + this.data.obj.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
	  if(this.data.action){
		  var self = this;
      wx.showLoading({
        title: '加载中...',
        mask: true
      })
		  ux.request(this.data.action,options,function(protocol){
        console.log(JSON.stringify(protocol.data.obj));
        wx.hideLoading();
        self.setData({
          obj:protocol.data.obj
        })
        WxParse.wxParse('articleDetail', 'html', protocol.data.obj.content, self, 5);
		  },true);
	  }    
  },
  
  onForm:function(event){
	if(this.data.submit){
		  var $this = this;
		  var dataset = event.currentTarget.dataset;
		  ux.request(this.data.submit,detail.value,function(protocol){
				if(protocol.success){
					if(dataset.url){
						wx.redirectTo(dataset.url);
					}
				}
		  },true);
	 }
  },
   backHome:function(){
     wx.reLaunch({
       url: '/pages/member/tab1/sugarSpice?id=' + this.data.obj.merchant,
     })
  },
  onTap:function(event){
	  var dataset = event.currentTarget.dataset;
	  var data = this.data;
	  if(dataset.key && dataset.val){
		  data[dataset.key] = dataset.val;
	  }
	  this.setData(data);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    var that = this;
    wx.showShareMenu({
      withShareTicket: true
    })
    var userInfo = this.data.userInfo;
    var obj = this.data.obj;
    console.log(obj.wechatTitle);
    var shareObj = {
      title: that.data.obj.title,
      path: '/pages/member/tab1/articel/articleDetail?&userId=' + userInfo.id + "&aId=" + that.data.obj.id,
      imageUrl: "",
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
          that.toast("转发成功");
        }
      },
      fail: function () {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          that.toast("取消转发");
        } else if (res.errMsg == 'shareAppMessage:fail') {
          that.toast("转发失败");
        }

      }
    }
    return shareObj;
  }
})
